package ch.janotta.slawo.utilities;

public final class Dice {
  // Don't allow to instantiate this utility class
  private Dice() {};

  /**
   * Simulates a roll of N six-sided dice with added bonus of M
   * @param n Number of D6 to roll
   * @param m Number to add after roll
   * @return Sum of the roll
   */
  public static int getND6PlusM(int n, int m) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += getD6();
    }
    sum += m;
    return sum;
  }

  /**
   * Generates a random integer in the range [1, 6] (inclusive boundaries)
   * @return
   */
  public static int getD6() {
    return getRandomNumber(6);
  }

  /**
   * Generates a random integer in the range [1, max] (inclusive boundaries)
   * @param max upper boundary
   * @return random number not less than 1 and not bigger than max
   */
  public static int getRandomNumber(int max) {
    return getRandomNumber(1, max);
  }

  /**
   * Generates a random integer in the range [min, max] (inclusive boundaries)
   * @param min lower boundary
   * @param max upper boundary
   * @return random number not less than min and not bigger than max
   */
  public static int getRandomNumber(int min, int max) {
    return (int) (Math.random() * (max - min + 1)) + min;
  }
}
